"""
数据透视表
"""

import numpy as np
import pandas as pd


def pivot_table_demo():
    """
    数据透视表
    :return:
    """
    df = pd.DataFrame({"A": ["one", "one", "two", "three"] * 3,
                       "B": ["A", "B", "C"] * 4,
                       "C": ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
                       "D": np.random.randint(1, 20, 12, dtype=np.int),
                       "E": np.random.randint(1, 20, 12, dtype=np.int)})
    print("df:\n", df)
    print("*" * 100)

    pivot_df = pd.pivot_table(df, values='D', index=["A", "B"], columns=["C"])
    print("透视之后的pivot_df:\n", pivot_df)
    print("*" * 100)


if __name__ == "__main__":
    pivot_table_demo()
